{{!
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
}}

<div id="stack-upgrade-dialog">
  <div {{bindAttr class="view.isLoaded::hidden :row-fluid"}}>
    <div class="span3 task-list-main-warp">{{statusIcon controller.upgradeData.Upgrade.request_status}}
      &nbsp;{{view.upgradeStatusLabel}}</div>
    <div class="span8">
      {{view App.ProgressBarView
        progressBinding="view.overallProgress"
        statusBinding="controller.upgradeData.Upgrade.request_status"
      }}
    </div>
    <div class="span1">
      {{view.overallProgress}}%
    </div>
  </div>

  <div class="task-list scrollable-block task-list-main-warp">
    {{#if view.isLoaded}}
      <div>
        {{#if view.runningItem}}
          <div class="box details-box">
            <div class="row-fluid">
              <div class="pull-left">{{t admin.stackUpgrade.dialog.inProgress}}&nbsp;{{view.runningItem.text}}</div>
              {{#if view.isDetailsOpened}}
                  <a href="#" class="pull-right" {{action toggleDetails target="view"}}>{{t admin.stackUpgrade.dialog.details.hide}}</a>
                {{#if view.runningItem.isTasksLoaded}}
                  <div class="clear">
                    {{view App.upgradeTaskView contentBinding="view.taskDetails" outsideViewBinding="view.outsideView"}}
                  </div>
                {{else}}
                  <div class="clear spinner"></div>
                {{/if}}
              {{else}}
                <a href="#" class="pull-right" {{action toggleDetails target="view"}}>{{t admin.stackUpgrade.dialog.details.open}}</a>
              {{/if}}
            </div>
          </div>
        {{/if}}
        {{#if view.failedItem}}
          <div class="box details-box">
            <div class="row-fluid">
              <div class="pull-left">{{t admin.stackUpgrade.dialog.failed}}&nbsp;{{view.failedItem.text}}</div>
              {{#if view.isDetailsOpened}}
                  <a href="#" class="pull-right" {{action toggleDetails target="view"}}>{{t admin.stackUpgrade.dialog.details.hide}}</a>
                {{#if view.failedItem.isTasksLoaded}}
                  <div class="clear">
                    {{view App.upgradeTaskView contentBinding="view.taskDetails" outsideViewBinding="view.outsideView"}}
                  </div>
                {{else}}
                  <div class="clear spinner"></div>
                {{/if}}
               {{else}}
                <a href="#" class="pull-right" {{action toggleDetails target="view"}}>{{t admin.stackUpgrade.dialog.details.open}}</a>
              {{/if}}
            </div>
            {{#if view.isHoldingState}}
              <div class="button-row">
                {{#if view.isDowngradeAvailable}}
                  <button class="btn btn-danger" {{bindAttr disabled="controller.requestInProgress"}} {{action confirmDowngrade view.failedItem target="controller"}}>{{t common.downgrade}}</button>
                {{/if}}
                {{#if view.failedItem.skippable}}
                  <button class="btn btn-warning" {{bindAttr disabled="controller.requestInProgress"}} {{action continue view.failedItem target="view"}}>{{t admin.stackUpgrade.dialog.continue}}</button>
                {{/if}}
                <button class="btn" {{bindAttr disabled="controller.requestInProgress"}} {{action retry view.failedItem target="view"}}>{{t common.retry}}</button>
              </div>
            {{/if}}
          </div>
        {{/if}}
        {{#if view.manualItem}}
          {{#if view.isFinalizeItem}}
            <div class="box details-box">
              <p><strong>{{t admin.stackUpgrade.dialog.manual}}</strong></p>
              {{#if isDowngrade}}
                <p>{{t admin.stackUpgrade.finalize.message.downgrade}}</p>
              {{else}}
                <p>{{t admin.stackUpgrade.finalize.message.upgrade}}</p>
              {{/if}}

              {{#if areSkippedServiceChecksLoaded}}
                {{#if skippedServiceChecks.length}}
                  <div>{{t admin.stackUpgrade.finalize.message.skippedServiceChecks}}</div>
                  <ul>
                    {{#each serviceName in skippedServiceChecks}}
                      <li>{{serviceName}}</li>
                    {{/each}}
                  </ul>
                  <div>{{t admin.stackUpgrade.finalize.message.testServices}}</div>
                {{/if}}
              {{else}}
                <div class="spinner"></div>
              {{/if}}

              <label class="message">
                {{view Em.Checkbox checkedBinding="view.isManualDone"}}
                {{t admin.stackUpgrade.dialog.manualDone}}
              </label>
              <div class="button-row">
                {{#if view.isDowngradeAvailable}}
                  <button class="btn btn-danger" {{bindAttr disabled="controller.requestInProgress"}} {{action confirmDowngrade view.manualItem target="controller"}}>{{t common.downgrade}}</button>
                {{/if}}
                <button class="btn" {{action closeWizard target="view.parentView"}}>{{t admin.stackUpgrade.finalize.later}}</button>
                <button class="btn btn-success" {{bindAttr disabled="view.isManualProceedDisabled"}} {{action complete view.manualItem target="view"}}>
                  {{t common.finalize}}
                </button>
              </div>
            </div>
          {{else}}
            <div class="box details-box">
              <p><strong>{{t admin.stackUpgrade.dialog.manual}}</strong></p>
              <p>{{view.manualItem.text}}</p>

              <label class="message">
                {{view Em.Checkbox checkedBinding="view.isManualDone"}}
                {{t admin.stackUpgrade.dialog.manualDone}}
              </label>
              <div class="button-row">
                {{#if view.isDowngradeAvailable}}
                  <button class="btn btn-danger" {{bindAttr disabled="controller.requestInProgress"}} {{action confirmDowngrade view.manualItem target="controller"}}>{{t common.downgrade}}</button>
                {{/if}}
                {{#if isDowngrade}}
                  <button class="btn" {{action closeWizard target="view.parentView"}}>{{t admin.stackUpgrade.pauseDowngrade}}</button>
                {{else}}
                  <button class="btn" {{action closeWizard target="view.parentView"}}>{{t admin.stackUpgrade.pauseUpgrade}}</button>
                {{/if}}
                <button class="btn btn-success" {{bindAttr disabled="view.isManualProceedDisabled"}} {{action complete view.manualItem target="view"}}>
                  {{t common.proceed}}
                </button>
              </div>
            </div>
          {{/if}}
        {{/if}}
        {{#if view.noActiveItem}}
          <div class="box details-box">
            <div>
              {{t admin.stackUpgrade.dialog.notActive}}
            </div>
          </div>
        {{/if}}
        {{#if App.upgradeAborted}}
          {{#unless requestInProgress}}
            <div class="box details-box">
              <label class="message">
                {{#if view.isDowngradeAvailable}}
                  {{t admin.stackUpgrade.dialog.aborted}}
                {{else}}
                  {{t admin.stackUpgrade.dialog.downgrade.aborted}}
                {{/if}}
              </label>
              <div class="button-row">
                {{#if view.isDowngradeAvailable}}
                  <button class="btn btn-danger" {{bindAttr disabled="controller.requestInProgress"}} {{action confirmDowngrade view.manualItem target="controller"}}>{{t common.downgrade}}</button>
                {{/if}}
                <button class="btn btn-success" {{action retryUpgrade target="controller"}}>
                  {{#if view.isDowngradeAvailable}}
                    {{t common.reUpgrade}}
                  {{else}}
                    {{t common.reDowngrade}}
                  {{/if}}
                </button>
              </div>
            </div>
          {{/unless}}
        {{/if}}
      </div>
      {{#each group in view.upgradeGroups}}
        {{#if group.isVisible}}
          {{view App.upgradeGroupView contentBinding="group"}}
        {{/if}}
      {{/each}}
    {{/if}}
  </div>
  {{#unless view.isLoaded}}
    <div class="spinner"></div>
  {{/unless}}
</div>
